/**
 * 
 */
package design_pattern.facade.security;

/**
 * 门面模式
 * 
 * @author linzq
 * 
 */
public class Facade {

  static private Facade instance;

  private Facade() {

  }

  static private synchronized void init() {
    if (instance == null) {
      instance = new Facade();
    }
  }

  static Facade getInstance() {
    if (instance == null) {
      init();
    }
    return instance;
  }

  // 以下是门面模式的核心代码
  static private Camera camera1 = new Camera(), camera2 = new Camera();
  static private Light light1 = new Light(), light2 = new Light(), light3 = new Light();
  static private Sensor sensor1 = new Sensor(), sensor2 = new Sensor();
  static private Alarm alarm1 = new Alarm();


  public void active() {
    camera1.turnOn();
    camera2.turnOn();
    light1.turnOn();
    light2.turnOn();
    light3.turnOn();
    sensor1.active();
    sensor2.active();
    alarm1.active();
  }

  public void deactive() {
    camera1.turnOff();
    camera2.turnOff();
    light1.turnOff();
    light2.turnOff();
    light3.turnOff();
    sensor1.deactive();
    sensor2.deactive();
    alarm1.deactive();
  }
}
